<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "../edit/index";
export default {
  mixins: [
    Vue.prototype.$vFN.Mixins.Base,
    Vue.prototype.$vFN.Mixins.Page,
    Vue.prototype.$vFN.Mixins.Table,
  ],
  components: {},
  data() {
    return {
      appWindow: window,
      // 页面接口地址
      apiUrl: {
        list: "mall-site-portal/offline-address/list",
        delete: "mall-site-portal/offline-address/delete",
        update: "mall-site-portal/offline-address/update",
        getItem: "mall-site-portal/offline-address/getItem",
      },

      // 表格数据删除展示结构
      tableDeleteConfig: {
        columns: [
          {
            label: "自提点名称",
            prop: "name",
            type: "",
          },
          {
            label: "联系电话",
            prop: "mobile",
          },
          {
            label: "是否显示",
            prop: "isOpen",
            type: "state-icon",
            options: {
              success: 1,
              error: 0,
            },
          },
        ],
      },

      mixinTable_tableSearchData: {
        name: "",
      },
    };
  },
  methods: {
    weekData(arr_) {
      console.log(arr_);
      let data_ = this.$vFN.Tools.toWeekString(JSON.parse(arr_));
      return data_;
    },

    // 打开添加/修改
    editBoxOpen(params_) {
      Edit.init({
        mixinEdit_parent: this,
        type: params_.type,
        id: params_.id,
        onSuccess: (res) => {
          this.mixinTable_refreshData();
        },
      });
    },

    async switchChange(event_, id_) {
      console.log(event_);
      console.log(id_);

      this.mixinTable_loading = true;
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.getItem,
          data: {
            id: id_,
          },
        },
        window
      );

      if (res._ok) {
        let updateData = {
          ...res.data,
        };

        updateData.isOpen = event_;

        let _data = await this.$vFN.Http.post(
          {
            url: this.apiUrl.update,
            data: updateData,
          },
          window
        );

        if (_data._ok) {
          this.$vFN.Tools.messageSuccess(res.message);
          this.mixinTable_refreshData();
        }
      }
      this.mixinTable_loading = false;
    },

    // 初始化
    async init() {
      this.mixinTable_initSearchData();
    },

    initData() {},
  },
  mounted() {
    this.init();
  },

  activated() {},
};
</script>
